package cn.org.mrliu.ssm.test.module.${modelNameUncapFirst};

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;

import com.alibaba.fastjson.JSON;

import cn.org.mrliu.ssm.common.test.ControllerTestSupport;
import cn.org.mrliu.ssm.model.${modelName};
import cn.org.mrliu.ssm.service.${modelName}Service;

public class Test${modelName}Controller extends ControllerTestSupport{

	@Resource
	private ${modelName}Service ${modelNameUncapFirst}Service;

	@Test
	public void index() throws Exception {
		MockHttpServletRequestBuilder createMessage = get("/${modelNameUncapFirst}");
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}
	
	@Test
	public void detail() throws Exception {
		MockHttpServletRequestBuilder createMessage = get("/${modelNameUncapFirst}/detail/1");
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}

	@Test
	public void add() throws Exception {
		MockHttpServletRequestBuilder createMessage = post("/${modelNameUncapFirst}/add");
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}

	@Test
	public void save() throws Exception {
		MockHttpServletRequestBuilder createMessage = post("/${modelNameUncapFirst}/save").param("name", "mock-add");
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}

	@Test
	public void edit() throws Exception {
		MockHttpServletRequestBuilder createMessage = post("/${modelNameUncapFirst}/edit/1");
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}

	@Test
	public void update() throws Exception {
		MockHttpServletRequestBuilder createMessage = post("/${modelNameUncapFirst}/update")
			.param("name", "mock-update")
			.param("id", "2");
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}

	@Test
	public void delete() throws Exception {
		MockHttpServletRequestBuilder createMessage = post("/${modelNameUncapFirst}/delete/1");
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}

	@Test
	public void list() throws Exception {
		MockHttpServletRequestBuilder createMessage = get("/${modelNameUncapFirst}/list");
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}

	@Test
	public void batchSave() throws Exception {
		List<${modelName}> ${modelNameUncapFirst}s = new ArrayList<>();
		${modelName} ${modelNameUncapFirst} = null;
		${modelNameUncapFirst} = new ${modelName}();
		${modelNameUncapFirst}.set${firstColumnNameCapFirst}("batchSave1");
		${modelNameUncapFirst}.set${firstColumnNameCapFirst}("batchSave2");
		${modelNameUncapFirst}.set${firstColumnNameCapFirst}("batchSave3");
		${modelNameUncapFirst}s.add(${modelNameUncapFirst});
		String json = JSON.toJSONString(${modelNameUncapFirst}s);

		MockHttpServletRequestBuilder createMessage = post("/${modelNameUncapFirst}/batchSave")
				.contentType("application/json;charset=utf-8").content(json);
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}

	@Test
	public void batchUpdate() throws Exception {
		MockHttpServletRequestBuilder createMessage = post("/${modelNameUncapFirst}/batchUpdate").param("name", "update...")
				.param("ids", "1_2_3_4_5");
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}

	@Test
	public void batchDelete() throws Exception {
		MockHttpServletRequestBuilder createMessage = post("/${modelNameUncapFirst}/batchDelete").param("ids", "1_2_3_4_5");
		mockMvc.perform(createMessage).andDo(print()).andReturn();
	}

}
